package zy04;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author czl
 * @Date 2024-04-07
 */
public class MainTest {
    public static void main(String[] args) {
        Student student = new Student();
        student.setName("傻椿");
        student.setSex("女");
        student.setHobby(new String[]{"吃","玩","乐"});

        Class<? extends Student> clazz = student.getClass();
        if (clazz.isAnnotationPresent(Info.class)) {
            Info annotation = clazz.getAnnotation(Info.class);
            String[] hobby = annotation.hobby();
            String sex = annotation.sex();

            if (!sex.contains(student.getSex())){
                throw new RuntimeException("性别只能是" + sex);
            }

            Set<String> set1 = new HashSet<>(Arrays.asList(hobby));
            Set<String> set2 = new HashSet<>(Arrays.asList(student.getHobby()));
            if (!set1.containsAll(set2)){
                throw new RuntimeException("爱好非法，爱好只能是：" + Arrays.toString(hobby)) ;
            }
        }

        System.out.println(student);
    }
}
